Skip to content

feat(SOSO-435): UnknownFieldPolicy strategy for DynamicTable#13

Merged
wagnert merged 1 commit intodevelopfrom
feature/SOSO-435-unknown-field-policy
Mar 11, 2026
Merged

feat(SOSO-435): UnknownFieldPolicy strategy for DynamicTable#13
wagnert merged 1 commit intodevelopfrom
feature/SOSO-435-unknown-field-policy

Conversation

@wagnert
Copy link
Member

@wagnert wagnert commented Mar 11, 2026

Summary

  • Introduces injectable UnknownFieldPolicyInterface (Strategy Pattern) to handle fields in row objects that are not defined in the table schema
  • DynamicTable now applies the policy before validation in add(), update(), and delete() operations
  • Default policy is StripUnknownFieldPolicy (silently removes unknown fields — safer default)

Changes

New Files (6)

File Description
src/types/policies.ts UnknownFieldPolicyInterface definition
src/utils/policies/StripUnknownFieldPolicy.ts Default: removes unknown fields
src/utils/policies/IgnoreUnknownFieldPolicy.ts Pass-through, no modification
src/utils/policies/ErrorUnknownFieldPolicy.ts Strict: throws ValidationError
src/utils/policies/index.ts Barrel export

Modified Files (4)

File Change
src/client/DynamicTable.ts Optional 3rd constructor param, policy applied in add(), update(), delete()
src/client/DynamicTableFactory.ts Optional 3rd constructor param, passes policy to DynamicTable
src/types/index.ts Re-export policies
src/utils/index.ts Re-export policies

New Tests (2 files, 34 tests)

File Tests
tests/utils/policies/UnknownFieldPolicies.test.ts 18 unit tests for all 3 policy implementations
tests/client/DynamicTable.unknownFields.test.ts 16 integration tests: DynamicTable with all policies + custom DI

Test Results

  • 306 tests pass (272 existing + 34 new)
  • 0 lint errors
  • No breaking changes (3rd constructor param is optional, default Strip is transparent for existing code)

Design Decisions

  • Strategy Pattern over string config — injectable implementations, not 'ignore' | 'warn' | 'strip' | 'error' strings
  • Same DI pattern as SelectorBuilderInterface — interface in types/, impl in utils/, optional constructor param with ?? new Default()
  • Library stays silent — no console.warn/console.log, communicates only via return values and exceptions
  • delete() covered — unknown fields in delete key objects are also processed

Related

Introduce injectable UnknownFieldPolicyInterface to handle fields in row
objects that are not defined in the table schema. DynamicTable now applies
the policy before validation in add(), update(), and delete() operations.

- Add UnknownFieldPolicyInterface in src/types/policies.ts
- Add 3 built-in policies in src/utils/policies/:
  - StripUnknownFieldPolicy (default): silently removes unknown fields
  - IgnoreUnknownFieldPolicy: passes rows through unchanged
  - ErrorUnknownFieldPolicy: throws ValidationError for unknown fields
- Extend DynamicTable constructor with optional 3rd param (default: Strip)
- Extend DynamicTableFactory constructor to pass policy through
- Add 18 unit tests for policy implementations
- Add 16 integration tests for DynamicTable with all policies + custom DI
- All 306 tests pass (272 existing + 34 new)
@wagnert wagnert merged commit 6e75228 into develop Mar 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant